package com.kai.mqtt.controller;

import com.kai.mqtt.auth.service.IMqttAclService;
import com.kai.mqtt.data.PageResult;
import com.kai.mqtt.data.Result;
import com.kai.mqtt.data.request.MqttAclRequest;
import com.kai.mqtt.data.request.MqttAclUpdateRequest;
import com.kai.mqtt.data.request.PageMqttAclRequest;
import com.kai.mqtt.data.response.MqttAclResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author weijk
 * @since 2024/8/18
 */
@RestController
@RequestMapping("/mqtt/acl")
public class MqttAclController {

    @Autowired
    private IMqttAclService mqttAclService;

    /**
     * 创建 acl
     *
     * @param request 参数
     * @return 结果
     */
    @PostMapping("/create")
    public Result<Boolean> createAcl(@RequestBody @Valid MqttAclRequest request) {
        return Result.success(mqttAclService.createAcl(request));
    }

    /**
     * 更新 acl
     *
     * @param request 参数
     * @return 结果
     */
    @PutMapping("/update")
    public Result<Boolean> updateAcl(@RequestBody @Valid MqttAclUpdateRequest request) {
        return Result.success(mqttAclService.updateAcl(request));
    }

    /**
     * 删除 acl
     *
     * @param id id
     * @return 结果
     */
    @DeleteMapping("/delete")
    public Result<Boolean> deleteAcl(@RequestParam("id") Integer id) {
        return Result.success(mqttAclService.deleteAcl(id));
    }

    /**
     * 分页查询 acl 列表
     *
     * @param request 参数
     * @return acl 列表
     */
    @PostMapping("/page")
    public PageResult<MqttAclResponse> pageAcl(@RequestBody PageMqttAclRequest request) {
        return mqttAclService.pageAcl(request);
    }
}
